#include "gofgame/common/ui/TextBox.h"

using namespace gofgame::common::ui;

TextBox::TextBox(
	CCScale9Sprite *normal9SpriteBg, 
	CCScale9Sprite *pressed9SpriteBg, 
	CCScale9Sprite *disabled9SpriteBg) 
	:Cocos2dxComponent(
		CCEditBox::create(
		CCSize((normal9SpriteBg ? normal9SpriteBg : getDefaultNormal9SpriteBg())->getContentSize()), 
			normal9SpriteBg ? normal9SpriteBg : getDefaultNormal9SpriteBg(),
			pressed9SpriteBg ? pressed9SpriteBg : getDefaultPressed9SpriteBg(),
			disabled9SpriteBg ? disabled9SpriteBg : getDefaultDisabled9SpriteBg()
		), 
		true
	) {	
}

void TextBox::visit() {
	CCEditBox *editBox = static_cast<CCEditBox*>(this->getContentNode());
	editBox->setPosition(CCPoint(this->getContentSize().width / 2, this->getContentSize().height / 2));
	editBox->setScaleX(this->getContentSize().width / editBox->getContentSize().width);
	editBox->setScaleY(this->getContentSize().height / editBox->getContentSize().height);
	Component::visit();
}

CCScale9Sprite *TextBox::getDefaultNormal9SpriteBg() {
	return CCScale9Sprite::create("gofgame/common/ui/TextBox.png");
}

CCScale9Sprite *TextBox::getDefaultPressed9SpriteBg() {
	return CCScale9Sprite::create("gofgame/common/ui/TextBox_pressed.png");
}

CCScale9Sprite *TextBox::getDefaultDisabled9SpriteBg() {
	return CCScale9Sprite::create("gofgame/common/ui/TextBox_disabled.png");
}

